﻿using Api.Common;
using AppManager.BLL;
using Newtonsoft.Json;
using PushManager.Model;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Mvc;


namespace PushManager.Web.Controllers
{
    public class ProjectController : Controller
    {
        /// <summary>
        /// 添加項目信息
        /// 两个文件名称CertUrl
        /// 测试文件名称SandBox_CertUrl
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Add(AddProjectModel model)
        {
            try
            {
                ProjectBLL.AddOrUpdate(model);
                return Json(new ApiResult { status = 100, msg = "操作成功" });

            }
            catch (ThreadAbortException ex)
            {

            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(JsonConvert.SerializeObject(ex));
            }
            return Json(new ApiResult { msg = "操作失敗" });
        }

        [HttpGet]
        public ActionResult List(GetProjectListModel model)
        {
            try
            {
                var projectList = ProjectBLL.GetList(model);
                return Json(new ApiResult { status = 100, data = projectList }, JsonRequestBehavior.AllowGet);

            }
            catch (ThreadAbortException ex)
            {

            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(JsonConvert.SerializeObject(ex));
            }
            return Json(new ApiResult { msg = "操作失敗" }, JsonRequestBehavior.AllowGet);
        }
    }
}